// common js functions

function sjax(AUrl) {
  // download single xml specification file
  var request = new XMLHttpRequest();
  if (!request) {
    alert('Your browser sucks, piss off!');
    return;
  }
  request.open("POST", AUrl, false);
  request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  request.send(null);
  if (request.status == 200) {
    // maps are returned as non-xml because they have different extension
    if (request.responseXML == null)
      return (new DOMParser()).parseFromString(request.responseText, "text/xml");
    return request.responseXML;
  } else
    alert('sjax: status='+request.status);
}

function debugClear() {
  // clear debug field
  var d = document.getElementById('debug');
  if (d)
    d.innerHTML = '';
}

function debug(AMessage) {
  // insert simple debug message to debug field
  var d = document.getElementById('debug');
  // if debug field does not exist, create it
  if (!d) {
    var d = document.createElement('pre');
    d.id = 'debug';
    d.setAttribute('style',"width: 600px; min-height: 800px; float: left; border: 1px dotted red;");
    document.body.insertBefore(d,document.body.firstChild);
  }
  // append debug message to the end of debug field
  d.innerHTML += AMessage+"\n";
}

function Stampt() {
  // auxiliary speed measurere in ms
  // Usage: var st = new Stampt(); doSomethingLong(); debug('  done in '+st.ms());
  this.start = new Date().getTime();
  this.ms = function() {
    return ((new Date().getTime())-this.start)+'ms';
  }
}